<template>
  <PageWrapper contentFullHeight>
    <CollapseContainer title="表单基础示例">
      <BasicForm @register="register" @submit="handleSubmit" @reset="handleReset" />
    </CollapseContainer>
  </PageWrapper>
</template>
<script lang="ts" setup>
  import { ref } from 'vue';
  import { BasicForm, FormSchema, useForm } from '@/components/Form';
  import { CollapseContainer } from '@/components/Container';
  import { PageWrapper } from '@/components/Page';

  import { useMessage } from '@/hooks/web/useMessage';

  const { createMessage } = useMessage();

  // prettier-ignore
  // 字段信息
  const schemas: FormSchema[] = [
    { field: 'field1',
      component: 'InputPassword',
      label: '基础',
      colProps: { span: 8 },
      componentProps:{
        placeholder:"请输入密码",
      },
    },
    { field: 'field4',
      component: 'InputPassword',
      label: '帮助信息',
      colProps: { span: 8 },
      helpMessage:"asdfa ",
    },
    { field: 'field4',
      component: 'InputPassword',
      label: '不显示明文按钮',
      colProps: { span: 8 },
      componentProps:{
        visibilityToggle:false,
      },
    },
    { field: 'field5',
      component: 'InputPassword',
      label: '必传',
      colProps: { span: 8 },
      required:true,
    },
    { field: 'field6',
      component: 'InputPassword',
      label: '校验规则',
      colProps: { span: 8 },
      required:true,
      rulesMessageJoinLabel:true,
      rules:[
        {
          max:12,
          min:6,
        }
      ]
    },
  ];

  const [register] = useForm({
    labelWidth: 120,
    schemas,
    actionColOptions: { span: 24 },
    fieldMapToTime: [['fieldTime', ['startTime', 'endTime'], 'YYYY-MM']],
  });

  const keyword = ref<string>('');

  // 重置方法
  function handleReset() {
    keyword.value = '';
  }

  // 提交方法
  function handleSubmit(values: any) {
    console.log('values', values);
    createMessage.success('click search,values:' + JSON.stringify(values));
  }
</script>
